﻿namespace WebPacker.Filters
{
	using System;
	using System.Globalization;
	using System.Text;
	using WebPacker.Packs;
	using Yahoo.Yui.Compressor;

	public sealed class YuiJavascriptMinifier : IFilter
	{
		public YuiJavascriptMinifier()
		{
			IsObfuscateJavascript = true;
			LineBreakPosition = -1;
			DisableOptimizations = false;
			PreserveAllSemicolons = false;
		}

		public string Name { get; set; }

		public bool PreserveAllSemicolons { get; set; }

		public bool DisableOptimizations { get; set; }

		public bool IsObfuscateJavascript { get; set; }

		public int LineBreakPosition { get; set; }

		public PackType PackType
		{
			get { return PackType.JavaScript; }
		}

		public string Apply(string content)
		{
			if (content == null)
			{
				throw new ArgumentNullException("content");
			}

			return content;
		}

		public string ApplyToCombined(string combinedContent)
		{
			return JavaScriptCompressor.Compress(combinedContent, false, IsObfuscateJavascript, PreserveAllSemicolons, DisableOptimizations, LineBreakPosition, Encoding.UTF8, CultureInfo.InvariantCulture);
		}
	}
}
